package com.PAT.UnSatisfying;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/12/22/10:59
 * @Description:
 * @Target: 差4
 */
public class 考试座位号 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int len = in.nextInt();
        SeatNumber[] seatNumbers = new SeatNumber[len];
        for (int i = 0; i < len; i++) {
            SeatNumber seatNumber = new SeatNumber(in.nextLong(),in.nextInt(),in.nextInt());
            seatNumbers[i] = seatNumber;
        }



        int len1 = in.nextInt();
        int[] ints = new int[len1];
        for (int i = 0; i < len1; i++) {
            ints[i] = in.nextInt();
        }


            for (int i = 0; i < len1; i++) {
                for (SeatNumber seatNumber : seatNumbers) {
                if (seatNumber.TestSeatNumber==ints[i]){
                    System.out.println(seatNumber.getId()+" "+seatNumber.getExamSeatNumber());
                }
            }
        }



    }



    static class SeatNumber{
        private long id;
        private int TestSeatNumber;
        private int ExamSeatNumber;


        public SeatNumber() {
        }

        public SeatNumber(long id, int testSeatNumber, int examSeatNumber) {
            this.id = id;
            TestSeatNumber = testSeatNumber;
            ExamSeatNumber = examSeatNumber;
        }


        public long getId() {
            return id;
        }

        public void setId(long id) {
            this.id = id;
        }

        public int getTestSeatNumber() {
            return TestSeatNumber;
        }

        public void setTestSeatNumber(int testSeatNumber) {
            TestSeatNumber = testSeatNumber;
        }

        public int getExamSeatNumber() {
            return ExamSeatNumber;
        }

        public void setExamSeatNumber(int examSeatNumber) {
            ExamSeatNumber = examSeatNumber;
        }

        @Override
        public String toString() {
            return "SeatNumber{" +
                    "id=" + id +
                    ", TestSeatNumber=" + TestSeatNumber +
                    ", ExamSeatNumber=" + ExamSeatNumber +
                    '}';
        }
    }
}
